/******************************************************************************
* File description: PureButton.qml : BaseButton.qml
* Function: 纯色按钮，继承自按钮基类
* Current Version: 1.0.0
* Author: 张宇轩
* Date: 2024-08-07
*  -----
*  Copyright by 博坤生物 .
 *****************************************************************************/
import QtQuick 2.14
import QtQuick.Layouts 1.14

Item {
    id: root
    /* property 定义开始 */
    // 全局
    property var mobileDevice: ["android", "ios"] // 不带鼠标的设备
    property var pc_otherDevice: ["windows", "linux"] // 带鼠标的设备
    // 目前使用上边方法判断是否带鼠标（不准确）
    property bool hoverEnable: (mobileDevice.indexOf(Qt.platform.os) === -1) ? true : false
    // 图片和文字布局
    property int labelPosition: GLOBAL.LabelPosition.Left // 默认左右布局
    property int pureGridTopMargin: 0
    property int pureGridBottomMargin: 0
    property int pureGridLeftMargin: 18
    property int pureGridRightMargin: 18

    // 按钮
    property bool isEnable: true
    property int pureBtnWidth: 120
    property int pureBtnHeight: 40
    property int pureBtnRadius: 4
    property string pureBtnColor: "#FFF"
    property int pureBtnBorderWidth: 1
    property string pureBtnBorderColor: "#999"
    property string pureHoveredBorderColor: "#999"

    // 文字
    property string pureFontColor: "#FF222222"
    property string pureFontFamily: "Alibaba PuHuiTi"
    property int pureFontPixelSize: 16
    property string pureText: "--Pure Default--"
    property string pureHoveredFontColor: "#FF222222"
    property bool btnIsLabelFillWidth: true
    property bool btnIsLabelFillHeight: true

    // 图片
    property int pureIconWidth: 20
    property int pureIconHeight: 20
    property bool isSquareIcon: true // 默认为方形Icon
    property bool isSvg: true // 默认为svg图片
    property url pureIconPath: "" // 图片路径

    // 按钮禁用
    property string disabledPureBtnBorderColor: "#D9D9D9"
    property string disabledPureBtnColor: "#F5F5F5"
    property string disabledpureFontColor: "#BFBFBF"

    // 信号
    signal entered();
    signal exited();
    signal pressed();
    signal released();
    /* property 定义结束 */

    BaseButton {
        id: pureBtn
        isEnable: root.isEnable
        labelPosition: root.labelPosition
        // 按钮
        btnWidth: pureBtnWidth
        btnHeight: pureBtnHeight
        btnColor: pureBtnColor
        btnRadius: pureBtnRadius
        btnBorderWidth: pureBtnBorderWidth
        btnBorderColor: pureBtnBorderColor

        // 文字
        btnIsLabelFillWidth: root.btnIsLabelFillWidth
        btnIsLabelFillHeight: root.btnIsLabelFillHeight
        btnFontFamily: pureFontFamily
        btnFontColor: pureFontColor
        btnFontPixelSize: pureFontPixelSize
        btnText: pureText

        // 图片
        btnIconWidth: pureIconWidth
        btnIconHeight: isSquareIcon ? pureIconWidth : pureIconHeight
        btnIsIconSquare: isSquareIcon
        isSvg: root.isSvg
        btnIconPath: pureIconPath

        // 禁用状态
        disabledBtnColor: disabledPureBtnColor
        disabledBtnTextColor: disabledpureFontColor
        disabledBtnBorderColor: disabledPureBtnBorderColor

        // 布局
        gridTopMargin: pureGridTopMargin
        gridBottomMargin: pureGridBottomMargin
        gridLeftMargin: pureGridLeftMargin
        gridRightMargin: pureGridRightMargin
        colSpacing: 10

        // 过渡动画
        // states: [
        //     State {
        //         name: "default"
        //         PropertyChanges {
        //             target: pureBtn
        //             btnFontColor: pureFontColor
        //             btnBorderColor: pureBtnBorderColor
        //         }
        //     },
        //     State {
        //         name: "hover"
        //         PropertyChanges {
        //             target: pureBtn
        //             btnFontColor: pureHoveredFontColor
        //             btnBorderColor: pureHoveredBorderColor
        //         }
        //     }
        // ]

        // transitions: [
        //     Transition {
        //         from: "default"
        //         to: "hover"
        //         NumberAnimation {
        //             target: pureBtn
        //             properties: "btnFontColor, btnBorderColor"
        //             duration: 30
        //         }
        //     },
        //     Transition {
        //         from: "hover"
        //         to: "default"
        //         NumberAnimation {
        //             target: pureBtn
        //             properties: "btnFontColor, btnBorderColor"
        //             duration: 30
        //         }
        //     }
        // ]

        MouseArea {
            enabled: isEnable
            hoverEnabled: hoverEnable
            anchors.fill: parent
            cursorShape: isEnable ? Qt.PointingHandCursor : Qt.ArrowCursor // 指针变为小手图标
            onEntered: {
                // console.log("悬停")
                pureBtn.state = "hover"
                root.entered()
            }
            onExited: {
                // console.log("离开")
                pureBtn.state = "default"
                root.exited()
            }
            onPressed: function(mouse){
                // console.log("按下")
                pureBtn.state = "hover"
                root.pressed()
            }
            onReleased: {
                // console.log("释放")
                pureBtn.state = "default"
                root.released()
            }
        }
    }
}
